package login;

//模型组件
import java.sql.*;
import java.util.*;

class LoginHandler {
	public LoginHandler(){}
	
	Connection conn;
	PreparedStatement ps;
	ResultSet rs;
	
//	检查是否已注册
	public boolean checkLogin(ArrayList arr){
//		从数据访问组件DBPool中取得连接
		conn = DBPool.getConnection();
		String name = (String)arr.get(0);
		String password = (String)arr.get(1);
		try{
			//String sql= "select * from cust_info where username='" + name + " ' and password='" + password +"'";
			String sql= "select * from user_info where username=? and password=?";
			ps = conn.prepareStatement(sql);
			ps.setString(1,name);
			ps.setString(2,password);
			rs=ps.executeQuery();
			if(rs.next()){
				DBPool.dbClose(conn,ps,rs);//释放资源
				return true;
			}
			else{
				DBPool.dbClose(conn,ps,rs);
				return false;
			}
		} catch (SQLException e){return false;}
	}
	

}
